# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=zxing-cpp
pkgver=2.2.1
pkgrel=1
arch="all"
url="https://github.com/zxing-cpp/zxing-cpp"
pkgdesc="C++ port of ZXing"
license="Apache-2.0"
makedepends="
	chrpath
	cmake
	gtest-dev
	py3-gpep517
	py3-pybind11-dev
	py3-setuptools
	python3-dev
	samurai
	stb
	"
source="https://github.com/zxing-cpp/zxing-cpp/archive/v$pkgver/zxing-cpp-v$pkgver.tar.gz
	setup.py
	"
subpackages="$pkgname-dev zxing py3-$pkgname:python"
options="!check"

prepare() {
	default_prepare

	cp "$srcdir"/setup.py "$builddir"
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_BLACKBOX_TESTS=OFF \
		-DBUILD_EXAMPLES=ON \
		-DBUILD_UNIT_TESTS="$(want_check && echo ON || echo OFF)" \
		-DBUILD_WRITERS=ON \
		-DBUILD_READERS=ON \
		-DBUILD_PYTHON_MODULE=on

	cmake --build build

	cp wrappers/python/pyproject.toml "$builddir"

	chrpath --delete "$builddir"/build/wrappers/python/*.so
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	ctest --test-dir build --output-on-failure -j1
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	rm "$pkgdir"/usr/lib/zxingcpp.cpython-*.so

	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

python() {
	depends="py3-pybind11"

	amove usr/lib/python*
}

zxing() {
	amove usr/bin
}

sha512sums="
f1de8df783061a152a18cd9102ac0c579c40c76ab4a5ba9f30bcb8ddb532f3fac08736840a631adbf7c30a7fa00ce8d65625c8cd695288620601708e8f256a53  zxing-cpp-v2.2.1.tar.gz
b3ccb7d9b28353dd1937dd2ce1af936eafced06f327cc39e461bed2afc46d4926a3a46e10a407683143fb552f0dbb89e245a2db9ee2be6c57e6ee0d09376bbe4  setup.py
"
